package com.hdu.hot100.oneDimensionalDp;

public class lc152 {
    class Solution {
        public int maxProduct(int[] nums) {
             int n = nums.length;

             double[] maxDP = new double[n];
             double[] minDP = new double[n];
             double ans = nums[0];
             maxDP[0] = nums[0];
             minDP[0] = nums[0];

             for (int i = 1; i < n; i++) {
                 double p1 = maxDP[i - 1] * nums[i];
                 double p2 = minDP[i - 1] * nums[i];
                 double p3 = nums[i];

                 maxDP[i] = Math.max(p1, Math.max(p2, p3));
                 minDP[i] = Math.min(p1, Math.min(p2, p3));
                 ans = Math.max(ans, maxDP[i]);
             }

             return ((int) ans);
        }
    }
}
